package com.biz.primus.ms.commodity.dao.ro;

import com.biz.primus.base.enums.ExtendType;
import com.biz.primus.base.redis.annotation.FieldSortedSet;
import com.biz.primus.base.redis.annotation.Ro;
import com.biz.primus.base.redis.bean.BaseRedisObject;
import com.biz.primus.commodity.vo.ExtendOptionVo;
import com.biz.primus.common.utils.JsonUtils;
import com.google.common.collect.Lists;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;

@Data
@Ro(key = "product:ExtendRo")
public class ExtendRo extends BaseRedisObject<String> implements Serializable {

    /**
     * 对应field
     */
    private String key;

    private String label;

    @FieldSortedSet(key = "categoryId", score = "idx")
    private Long categoryId;

    private Integer idx;

    /**
     * 属性值  jsonArray
     * @see ExtendOptionVo
     */
    private String option;

    private ExtendType extendType;

    public List<ExtendOptionVo> getOptions(){
        if (StringUtils.isNotBlank(option)){
            return JsonUtils.json2Obj(option, List.class, ExtendOptionVo.class);
        }
        return Lists.newArrayList();
    }
}
